package ch.ifage.business.dom;

import java.util.GregorianCalendar;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;


/**
 * test workflows.
 * @author Christian
 *
 */
public class WorkflowsTest {

	/**
	 * les workflows.
	 */
	private Workflows wfs;
	
	/**
	 * workflow de l'init.
	 */
	private Workflow w1;
	
	/**
	 * Initializes the unit test.
	 */
	@Before
	public final void init() {
		StepIdentity   si = new StepIdentity(1, "serveur1", "instance1");
		GregorianCalendar start = new GregorianCalendar();
		GregorianCalendar end = new GregorianCalendar();
		end.add(GregorianCalendar.SECOND, 1);
		StepProperties sp = new StepProperties("avis.xml", start, end,
		           							    Activity.ROUTER,
		           							    "application1",
		           							    Status.SUCCESS,
		           							    "Log du routeur\n ligne 1\n Fin");
		FirstStep s1 = new FirstStep(si, sp);
	
		w1 = new Workflow(s1);
		
		wfs = new Workflows();
		
		wfs.add(w1); 
		
		System.out.println(wfs.toString());
		
	}

	
	
	/**
	 * test.
	 */
	@Test
	public final void testGetList() {
		Assert.assertTrue(wfs.getList().size() == 1);
	}

	/**
	 * test.
	 */
	@Test
	public final void testAdd() {
		StepIdentity   si = new StepIdentity(1, "serveur1", "instance1");
		GregorianCalendar start = new GregorianCalendar();
		GregorianCalendar end = new GregorianCalendar();
		start.add(GregorianCalendar.SECOND, 1);
		end.add(GregorianCalendar.SECOND, 3);
		StepProperties sp = new StepProperties("avis2.xml", start, end,
		           							    Activity.ROUTER,
		           							    "application2",
		           							    Status.SUCCESS,
		           							    "Log du routeur\n ligne 1\n Fin");
		FirstStep s2 = new FirstStep(si, sp);
	
		Workflow w2 = new Workflow(s2);
		
		wfs.add(w2); 
	}
	
	/**
	 * test toString.
	 * le big test.
	 */
	@Test
	public final void testToString() {
		System.out.println("-------------------------");
		System.out.println("Test toString Worflows");
		System.out.println("-------------------------");
		System.out.println("----- 1 wf avec 1 étape:");
		System.out.println(wfs.toString());
		
		System.out.println("----- 2 wf:");
		StepIdentity   si = new StepIdentity(2, "serveur1", "instance1");
		GregorianCalendar start = new GregorianCalendar();
		GregorianCalendar end = new GregorianCalendar();
		start.add(GregorianCalendar.SECOND, 1);
		end.add(GregorianCalendar.SECOND, 3);
		StepProperties sp = new StepProperties("avis2.xml", start, end,
		           							    Activity.ROUTER,
		           							    "application2",
		           							    Status.SUCCESS,
		           							    "Log du routeur\n ligne 1\n Fin");
		FirstStep s2 = new FirstStep(si, sp);
		Workflow w2 = new Workflow(s2);
		wfs.add(w2);
		System.out.println(wfs.toString());

		System.out.println("----- 2 wf, dont 1 avec 2 étape:");
		StepIdentity si3 = new StepIdentity(3, "serveur1", "instance1");
		new Step(si3, sp, s2);
		System.out.println(wfs.toString());
		System.out.println("-----------------------------------");
		
		System.out.println("----- 2 wf, dont 1 avec 3 étape:");
		StepIdentity si4 = new StepIdentity(4, "serveur1", "instance1");
		new Step(si4, sp, s2);
		System.out.println(wfs.toString());
		System.out.println("-----------------------------------");
		
	}
	
	/**
	 * Test method for {@link ch.ifage.business.dom.workflow#getSubSetList(string))}.
	 */
	@Test
	public final void testgetSubSetList() {
		Assert.assertTrue(wfs.getSubSetList("routeur").size() == 1);
		Assert.assertTrue(wfs.getSubSetList("ROUteur").size() == 1);
		Assert.assertTrue(wfs.getSubSetList("ROUteurXXX").size() == 0);
		
		StepIdentity   si = new StepIdentity(2, "serveur1", "instance1");
		GregorianCalendar start = new GregorianCalendar();
		GregorianCalendar end = new GregorianCalendar();
		start.add(GregorianCalendar.SECOND, 1);
		end.add(GregorianCalendar.SECOND, 3);
		StepProperties sp = new StepProperties("avis2.xml", start, end,
		           							    Activity.ROUTER,
		           							    "application2",
		           							    Status.SUCCESS,
		           							    "Log du routeur special\n ligne 1\n Fin");
		FirstStep s2 = new FirstStep(si, sp);
		Workflow w2 = new Workflow(s2);
		wfs.add(w2);
	
		Assert.assertTrue(wfs.getSubSetList("routeur").size() == 2);
		Assert.assertTrue(wfs.getSubSetList("special").size() == 1);
		Assert.assertTrue(wfs.getSubSetList("very special").size() == 0);

	}

}
